﻿using AutoMapper;
using MediatR;
using T_vehicle.API.Application.Command.RepairRecordsCommand;
using T_vehicle.Domain;
using T_vehicle.Infrastructure.Interfacec;

namespace T_vehicle.API.Application.CommandHandlers.RepairRecordsCommandHandlers
{
    public class AddRepairRecordsCommandHandlers : IRequestHandler<AddRepairRecordsCommand, int>
    {
        private readonly IRepairRepository repairRepository;
        private readonly IMapper mapper;

        public AddRepairRecordsCommandHandlers(IRepairRepository repairRepository, IMapper mapper)
        {
            this.repairRepository = repairRepository;
            this.mapper = mapper;
        }


        public async Task<int> Handle(AddRepairRecordsCommand request, CancellationToken cancellationToken)
        {

            var info = mapper.Map<RepairRecords>(request);
            info.CreateDate = DateTime.Now;
            return await repairRepository.AddAsync(info);


            //var info = new RepairRecords();
            //info.MaintenanceTitle = request.MaintenanceTitle;
            //info.MaintenanceType = request.MaintenanceType;
            //info.LicenNumber = request.LicenNumber;
            //info.MaintenanceMoney = request.MaintenanceMoney;
            //info.Head = request.Head;
            //info.Description = request.Description;
            //info.MaintenanceDate = request.MaintenanceDate;
            //info.Remark = request.Remark;
            //info.CreateDate = DateTime.Now;
            //return await repairRepository.AddAsync(info);
        }
    }
}
